package com.ling.module1sbbyyds.controller.usercenter;

import com.ling.sbbyyds.entity.users.User;
import com.ling.module1sbbyyds.service.news.usercenter.UserService;
import com.ling.sbbyyds.interaction.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 天道酬勤、学无止境
 *
 * @Description: 类描述
 * @author: ling
 * @date: 2022年03月26日
 */
@RestController
@Validated
@RequestMapping("api/user/")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("isLogin/uploadImage")
    public ResultVo uploadImage(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws IOException {
        return userService.uploadImageImpl(file, request);
    }

    @GetMapping("isLogin/personalInformation")
    public ResultVo personalInformation() {
        return userService.personalInformation();
    }

    /**
     * @Description: 获取个人信息  根据id
     * @author: ling
     * @date: 2022/5/8
     * @Return: com.ling.module1sbbyyds.interaction.Return.Result
     */
    @GetMapping("personalInformation/{userId}")
    public ResultVo personalInformationById(@PathVariable Long userId) {
        return userService.personalInformationById(userId);
    }

    @GetMapping("isLogin/updatePersonalInformation")
    public ResultVo updatePersonalInformation(User user, HttpServletRequest request) {
        return userService.updatePersonalInformation(user, request);
    }

    @GetMapping("isLogin/getPostsList")
    public ResultVo getPostsList(@RequestParam(required = false) Integer currentPage,@RequestParam(required = false) Integer limit) {
        return userService.getPostsList(currentPage,limit);
    }

    @GetMapping("getOtherUser")
    public ResultVo getOtherUser(@RequestParam String userId) {
        return userService.getOtherUser(userId);
    }

    /**
     * @param verificationCode: 验证码
     * @param newPassword:      确认密码
     * @Description: 修改密码
     * @author: ling
     * @date: 2022/5/27
     * @Return: com.ling.module1sbbyyds.interaction.Return.
     */
    @PostMapping("isLogin/changePassword")
    public ResultVo changePassword(@RequestParam String verificationCode,
                                   @RequestParam String newPassword
            , HttpServletRequest request) {
        return userService.changePassword(verificationCode, newPassword, request);
    }


    /**
     * @param userId: 用户id
     * @Description: 获取用户历史发布的文章图片
     * @author: ling
     * @date: 2022/5/27
     * @Return: com.ling.module1sbbyyds.interaction.Return.Result
     */
    @GetMapping("getUserImages")
    public ResultVo getUserImages(@RequestParam String userId) {
        return userService.getUserImages(userId);
    }


    /**
     * user/updatePassword
     * 修改密码
     *
     * @param phone           手机号
     * @param password        新密码
     * @param confirmPassword 确认密码
     * @return
     */
    @PostMapping("updatePassword")
    public ResultVo updatePassword(@RequestParam("phone") String phone, @RequestParam("password") String password,
                                   @RequestParam("confirmPassword") String confirmPassword) {
        return userService.updatePassword(phone, password, confirmPassword);
    }

    /**
     * user/checkByCode
     * 校验验证码是否正确
     *
     * @param phone
     * @param code
     * @return
     */
    @GetMapping("checkByCode")
    public ResultVo checkByCode(@RequestParam("phone") String phone, @RequestParam("code") String code) {
        return userService.checkByCode(phone, code);
    }

}
